package com.ely.coupon.distribute.listener;

import com.ely.coupon.common.core.constants.MessageConstants;
import com.ely.coupon.distribute.service.CouponDistributeService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(consumerGroup = MessageConstants.ConsumerGroup.MEMBER_COUPON_GROUP, topic = MessageConstants.Topic.TOPIC_MEMBER_REGISTER)
public class MemberRegisterListener implements RocketMQListener<String> {
    @Resource
    private CouponDistributeService couponDistributeService;

    /**
     * 使用去重表解决幂等性的问题
     *
     * @param memberId
     */
    @Override
    public void onMessage(String memberId) {
        couponDistributeService.save(Long.parseLong(memberId));
    }
}

